<?php
class Pageley_Tag_Image extends Pageley_Tag_Abstract {
    
    private $file;
    private $width;
    private $height;
    
    public function execute() {
        $source = new Pageley_Util_Image($this->file->getFile());
        $width = $this->width;
        $height = $this->height;
        if($width > $source->getWidth()) {
            $width = $source->getWidth();
        }
        if($height > $source->getHeight()) {
            $height = $source->getHeight();
        }
        $destination = $source->resize($width, $height);
        $fileManager = $this->file->getFileManager();
        $location = $fileManager->resolveLocation($destination->getFile());
        $imageFile = new Pageley_Domain_ImageFile($location, $destination->getWidth(), $destination->getHeight());
        $imageFile->setFileManager($fileManager);
        return $imageFile;
    }
    
    public function setFile($file) {
        $this->file = $file;
    }
    
    public function setWidth($width) {
        $this->width = $width;
    }
    
    public function setHeight($height) {
        $this->height = $height;
    }
}